package Lists.DoubleLinkedList;

public class p_reserve {
    //原理和单链表反转相同
    public static void reserve(DoubleListNode head) {
        DoubleListNode pre = null;
        DoubleListNode next = null;
        while (head != null) {
            next = head.next;//便于链表的数据更新
            head.next = pre;//进行后面链表的双向链接
            head.last = next;//进行前面链表的双向链接
            pre = head;//数据的更新
            head = next;//链表的节点更新
        }
    }
}
/*
* null ← [1] ⇄ [2] ⇄ [3] → null
* 第1次循环
java
next = head.next;    // next = [2]
head.next = pre;     // [1].next = null
head.last = next;    // [1].last = [2]
pre = head;          // pre = [1]
head = next;         // head = [2]
链表状态变化：
初始状态：
null ← [1] ⇄ [2] ⇄ [3] → null
操作后：
null ← [2] ⇄ [1] → null
[3] 暂时断开（由 next 保存）
* 指针状态：
text
pre: [1] (next=null, last=[2])
head: [2]
next: [2]*/